package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        //文件输出流(字节流  低级流):负责将字节写入到文件中
        FileOutputStream fos = new FileOutputStream("pw.txt",true);
        //转换输出流(字符流  高级流): 1 负责衔接字节和字符流 2 负责将写出的字符转换为字节
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //缓冲输出流(字符流  高级流) 负责块写文本数据加速
        BufferedWriter bw = new BufferedWriter(osw);
        //PrintWriter(字符流,高级流)1 按行写出字符串 2  自动行刷新
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner scan = new Scanner(System.in);

        while (true){
            System.out.println("请输入");
            String s = scan.nextLine();
            if (s.equals("exit")){
                pw.close();
                break;
            }else {
                pw.println(s);
            }
        }
        System.out.println("写入完毕!!!!!!");
    }
}
